unit uniFuncBD;

interface

uses
  SysUtils, Classes, DB, DBTables, ADODB;

Const
     CRLF = #10+#13;

function retorna_inteiro(parCampo, parSQL:string;AParams: TParameters = nil) : Integer;
function retorna_string(parCampo, parSQL:string;AParams: TParameters = nil) : String;
function retorna_currency(parCampo, parSQL:string;AParams: TParameters = nil) : Currency;
function retorna_double(parCampo, parSQL:string;AParams: TParameters = nil) : Double;

function retorna_data(parCampo, parSQL:string;AParams: TParameters = nil) : TDateTime;

function existe_Valor(parSQL : string;AParams: TParameters = nil) : boolean;

implementation

uses uniDtmSisnnovi;

function retorna_inteiro(parCampo, parSQL:string;AParams: TParameters = nil) : Integer;
var qryTemp : TADOQuery;
begin
  qryTemp := DtmSisnnovi.NewQuery(parSQL,AParams);
  if qryTemp.RecordCount > 0 then
  begin
    Result := qryTemp.fieldbyname(parCampo).asInteger;
    qryTemp.free;
    exit;
  end;
  Result := 0;
end;

function retorna_string(parCampo, parSQL:string;AParams: TParameters = nil) : String;
var qryTemp : TADOQuery;
begin
  qryTemp := DtmSisnnovi.NewQuery(parSQL,AParams);
  if qryTemp.RecordCount > 0 then
  begin
    Result := qryTemp.fieldbyname(parCampo).asString;
    qryTemp.free;
    exit;
  end;
  Result := '';
end;

function retorna_currency(parCampo, parSQL:string;AParams: TParameters = nil) : Currency;
var qryTemp : TADOQuery;
begin
  qryTemp := DtmSisnnovi.NewQuery(parSQL,AParams);
  if qryTemp.RecordCount > 0 then
  begin
    Result := qryTemp.fieldbyname(parCampo).AsCurrency;
    qryTemp.free;
    exit;
  end;
  Result := 0;
end;

function retorna_double(parCampo, parSQL:string;AParams: TParameters = nil) : Double;
var qryTemp : TADOQuery;
begin
  qryTemp := DtmSisnnovi.NewQuery(parSQL,AParams);
  if qryTemp.RecordCount > 0 then
  begin
    Result := qryTemp.fieldbyname(parCampo).AsFloat;
    qryTemp.free;
    exit;
  end;
  Result := 0;
end;


function existe_valor(parSQL:string;AParams: TParameters = nil) : boolean;
var qryTemp : TADOQuery;
begin
  Result := False;
  qryTemp := DtmSisnnovi.NewQuery(parSQL,AParams);
  if qryTemp.RecordCount > 0 then
  begin
    Result := True;
    exit;
  end;
  qryTemp.free;
end;

function retorna_data(parCampo, parSQL:string;AParams: TParameters = nil) : TDateTime;
var qryTemp : TADOQuery;
begin
  qryTemp := DtmSisnnovi.NewQuery(parSQL,AParams);
  if qryTemp.RecordCount > 0 then
  begin
    Result := qryTemp.fieldbyname(parCampo).asDateTime;
    qryTemp.free;
    exit;
  end;
end;
end.
